package com.nancal.activiti.service.impl;

        import com.google.errorprone.annotations.Var;
        import com.nancal.activiti.dao.UserDao;
        import com.nancal.activiti.entity.pojo.ProcessUser;
        import com.nancal.activiti.service.UserService;
        import lombok.extern.slf4j.Slf4j;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.stereotype.Service;
        import org.springframework.transaction.annotation.Transactional;

        import java.util.ArrayList;
        import java.util.HashMap;
        import java.util.List;
        import java.util.Map;

@Slf4j
@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

  /* @Override
    public void updateUser(String id) {

        userDao.updateUser(id);
    }*/

    @Override
    public ProcessUser queryUserByName(String name) {
        return userDao.queryUserByName(name);
    }

    @Override
    public void updateUser(ProcessUser user, String groupId) {
        //修改用户
        userDao.updateUser(user);
        //删除关系
        userDao.delMemberShip(user.getId());
        //创建关系
        if(user.getId() != null && groupId != null && groupId.length()> 0){
            userDao.setMemberShip(user.getId(),groupId);
        }
    }

    @Override
    public List<Map<String, String>> queryAllUser() {
        List<String> names = userDao.queryAllUser();
        ArrayList<Map<String, String>> maps = new ArrayList<>();
        for (String name : names) {
            HashMap<String, String> hashMap = new HashMap<>();
            hashMap.put("name",name);
            hashMap.put("value",name);
            maps.add(hashMap);
        }
        return maps;
    }

}
